//第一版API接口解析
import parser from 'fast-xml-parser'

const xmlConfig = {
	trimValues: true,
	textNodeName: 'list',
	ignoreAttributes: false,
	attributeNamePrefix: '',
	parseAttributeValue: true
}
class ToolsV1 {
	constructor() {

	}
	isXml(text) {
		var xmlPattern = new RegExp("<?xml[^>]*>", "g")
		return xmlPattern.test(text)
	}
	videoClass(data) {
		// console.log(data)
		let res = parser.parse(data.data, xmlConfig)
		let { ty } = res.rss.class
		let list = new Array()
		for (let v of ty) {
			let item = {
				tid: v.id,
				name: v.list
			}
			list.push(item)
		}
		// console.log(list)
		return list
	}
	videoList(data) {
		// console.log(data)
		let res = parser.parse(data.data, xmlConfig)
		// console.log(res)
		let { page, pagecount, pagesize, recordcount, video } = res.rss.list
		let videos = new Array()
		for (let v of video) {
			let item = {
				vod_id: v.id,
				vod_pic: v.pic,
				vod_name: v.name,
				type_name: v.type,
				vod_sub: v.note,
				vod_year: v.year
			}
			videos.push(item)
		}
		let obj = { pagecount, pagesize, recordcount, page, videos }
		// console.log(obj)
		return obj
	}

	videoDetail(data) {
		// console.log(data)
		let res = parser.parse(data.data, xmlConfig)
		let { page, pagecount, pagesize, recordcount, video } = res.rss.list
		// console.log(video)
		let item = {
			vod_id: video.id,
			vod_pic: video.pic,
			vod_name: video.name,
			type_name: video.type,
			vod_sub: video.note,
			vod_year: video.year,
			vod_director: video.director,
			vod_actor: video.actor,
			vod_content: video.des,
			vod_lang: video.lang,
			vod_area: video.area
		}
		// console.log(video)
		let m3u8List = []
		for (let v of video.dl.dd) {
			let urls = v.list.split('#')
			for (let u of urls) {
				if (u.includes('m3u8'))
					m3u8List.push(u)
			}
		}
		let obj = { data: item, m3u8List }
		// console.log(obj)
		return obj
	}
}




export default new ToolsV1
/*

{
  "data": {
    "vod_id": 16994,
    "type_id": 38,
    "type_id_1": 34,
    "group_id": 0,
    "vod_name": "你不是她粤语",
    "vod_sub": "",
    "vod_en": "nibushitayueyu",
    "vod_status": 1,
    "vod_letter": "N",
    "vod_color": "",
    "vod_tag": "",
    "vod_class": "剧情,爱情,家庭",
    "vod_pic": "http://jingpinzy1.com/upload/vod/20231228-1/9f41f93bdd665cf4f454c15e503c4c93.jpg",
    "vod_pic_thumb": "",
    "vod_pic_slide": "",
    "vod_pic_screenshot": "",
    "vod_actor": "丁子朗,冯盈盈,姚嘉妮,张颕康,车婉婉,马贯东",
    "vod_director": "徐正康,陈萍",
    "vod_writer": "麦世龙,严丽华,郑子涛",
    "vod_behind": "",
    "vod_blurb": "林信（丁子朗饰）与夏莉（冯盈盈饰）拍拖三年，两人的价值观和对将来的愿景存在分歧，感情陷入瓶颈。他俩经历一场车祸，莉竟如奇迹般丝毫无损，更由一位平实乏味的伴侣转变成男人梦寐以求的浪漫情人，令信怀疑车祸中",
    "vod_remarks": "更新至13集",
    "vod_pubdate": "2023-12-25",
    "vod_total": 15,
    "vod_serial": "",
    "vod_tv": "",
    "vod_weekday": "",
    "vod_area": "中国香港",
    "vod_lang": "粤语",
    "vod_year": "2023",
    "vod_version": "",
    "vod_state": "正片",
    "vod_author": "豆瓣",
    "vod_jumpurl": "",
    "vod_tpl": "",
    "vod_tpl_play": "",
    "vod_tpl_down": "",
    "vod_isend": 0,
    "vod_lock": 0,
    "vod_level": 0,
    "vod_copyright": 0,
    "vod_points": 0,
    "vod_points_play": 0,
    "vod_points_down": 0,
    "vod_hits": 0,
    "vod_hits_day": 0,
    "vod_hits_week": 0,
    "vod_hits_month": 0,
    "vod_duration": "",
    "vod_up": 0,
    "vod_down": 0,
    "vod_score": "0.0",
    "vod_score_all": 0,
    "vod_score_num": 0,
    "vod_time": "2024-01-10 20:37:31",
    "vod_time_add": 1703768977,
    "vod_time_hits": 0,
    "vod_time_make": 0,
    "vod_trysee": 0,
    "vod_douban_id": 36071665,
    "vod_douban_score": "0.0",
    "vod_reurl": "",
    "vod_rel_vod": "",
    "vod_rel_art": "",
    "vod_pwd": "",
    "vod_pwd_url": "",
    "vod_pwd_play": "",
    "vod_pwd_play_url": "",
    "vod_pwd_down": "",
    "vod_pwd_down_url": "",
    "vod_content": "<p>林信（丁子朗饰）与夏莉（冯盈盈饰）拍拖三年，两人的价值观和对将来的愿景存在分歧，感情陷入瓶颈。他俩经历一场车祸，莉竟如奇迹般丝毫无损，更由一位平实乏味的伴侣转变成男人梦寐以求的浪漫情人，令信怀疑车祸中到底发生了什么？信受伤期间，竞争对手骆伟滔（张颕康饰）接管了信负责的项目和人手，并将信投闲置散。滔喜欢上司麦美娜（姚嘉妮饰），娜职场得意却婚姻失意，和丈夫关系早已破裂。滔因害怕改变现状而不敢对娜展开追求，而莉竟令这感情枷锁出现转机……</p>",
    "vod_play_from": "ckm3u8",
    "vod_play_server": "no",
    "vod_play_note": "",
    "vod_play_url": "第01集$https://www.ldxmcloud.com/20231228/Mo8lyv8d/index.m3u8#第02集$https://www.ldxmcloud.com/20231228/ae0hT1IS/index.m3u8#第03集$https://www.ldxmcloud.com/20231228/bbH4kqPu/index.m3u8#第04集$https://www.ldxmcloud.com/20231228/0jDVnTwM/index.m3u8#第05集$https://www.ldxmcloud.com/20231229/rOC9VnCi/index.m3u8#第06集$https://www.ldxmcloud.com/20240101/vBMqVBbt/index.m3u8#第07集$https://www.ldxmcloud.com/20240102/VdRuiDdj/index.m3u8#第08集$https://www.ldxmcloud.com/20240103/k5KmWJas/index.m3u8#第09集$https://www.ldxmcloud.com/20240104/bBecaSZE/index.m3u8#第10集$https://www.ldxmcloud.com/20240105/ZBTkDCXj/index.m3u8#第11集$https://www.ldxmcloud.com/20240108/ueNim3QZ/index.m3u8#第12集$https://www.ldxmcloud.com/20240109/9CWQT488/index.m3u8#第13集$https://www.ldxmcloud.com/20240110/VJ5uCiDh/index.m3u8",
    "vod_down_from": "",
    "vod_down_server": "",
    "vod_down_note": "",
    "vod_down_url": "",
    "vod_plot": 0,
    "vod_plot_name": "",
    "vod_plot_detail": "",
    "type_name": "港台剧"
  },
  "m3u8List": [
    "第01集$https://www.ldxmcloud.com/20231228/Mo8lyv8d/index.m3u8",
    "第02集$https://www.ldxmcloud.com/20231228/ae0hT1IS/index.m3u8",
    "第03集$https://www.ldxmcloud.com/20231228/bbH4kqPu/index.m3u8",
    "第04集$https://www.ldxmcloud.com/20231228/0jDVnTwM/index.m3u8",
    "第05集$https://www.ldxmcloud.com/20231229/rOC9VnCi/index.m3u8",
    "第06集$https://www.ldxmcloud.com/20240101/vBMqVBbt/index.m3u8",
    "第07集$https://www.ldxmcloud.com/20240102/VdRuiDdj/index.m3u8",
    "第08集$https://www.ldxmcloud.com/20240103/k5KmWJas/index.m3u8",
    "第09集$https://www.ldxmcloud.com/20240104/bBecaSZE/index.m3u8",
    "第10集$https://www.ldxmcloud.com/20240105/ZBTkDCXj/index.m3u8",
    "第11集$https://www.ldxmcloud.com/20240108/ueNim3QZ/index.m3u8",
    "第12集$https://www.ldxmcloud.com/20240109/9CWQT488/index.m3u8",
    "第13集$https://www.ldxmcloud.com/20240110/VJ5uCiDh/index.m3u8"
  ]
}

*/